import { createStore } from 'vuex'
import axios from 'axios'
export default createStore({
  state: {
    isTabbarShow: true,
    city: { cityId: 110100, name: '北京', pinyin: 'beijing', isHot: 1 },
    nowPlayingList: [],
    nowPlayingTotal: 1,
    commingSoonList: [],
    commingSoonTotal: 1,
    cinemaList: []
  },
  mutations: {
    ToggleTabbarShow (state, data) {
      state.isTabbarShow = data
    },
    ChangCity (state, data) {
      state.city = data
    },
    nowPlayingData (state, data) {
      if (data) {
        state.nowPlayingList = [...state.nowPlayingList, ...data.films]
        state.nowPlayingTotal = data.total
      } else {
        state.nowPlayingList = []
      }
    },
    commingSoonData (state, data) {
      if (data) {
        state.commingSoonList = [...state.commingSoonList, ...data.films]
        state.commingSoonTotal = data.total
      } else {
        state.commingSoonList = []
      }
    },
    cinemaData (state, data) {
      state.cinemaList = data.cinemas
    }
  },
  actions: {
    getAxiosData (store, data) {
      axios({
        url: data.url,
        headers: {
          'X-Client-Info': `{"a":"3000","ch":"1002","v":"5.0.4","e":"16151016671203561505488897","bc":${store.state.city.cityId}}`,
          'X-Host': data.host
        }
      }).then(res => {
        store.commit(data.fun, res.data.data)
      })
    }
  },
  modules: {}
})
